using CNRegex.Entity;
using NHibernate.Linq;
using System.Linq;
using CNRegex.Entity.EntityEx;
using Project.Common;
using System;
using System.Collections.Generic;
using NHibernate;
namespace CNRegex.Dal.DataAccess {
	public partial class DalRegexUserBlog 
	{
		private DalRegexUserBlogContent dalRegexUserBlogContent;
		private DalRegexBook dalRegexBook;
		private void Initialize()
		{

		}
		
		public void Create(RegexUserBlog model, RegexUserBlogContent contentModel)
		{
			//dalRegexUserBlogContent = DalFactory.Get<DalRegexUserBlogContent>(this.Session);
			ITransaction tx = this.Session.BeginTransaction();
			using (tx)
			{
				this.Save(model);
				contentModel.BlogID = model.ID;
				dalRegexUserBlogContent.Save(contentModel);
				tx.Commit();
			}
		}

		public void Save(RegexUserBlog model, RegexUserBlogContent contentModel)
		{
			//dalRegexUserBlogContent = DalFactory.Get<DalRegexUserBlogContent>(this.Session);
			ITransaction tx = this.Session.BeginTransaction();
			using (tx)
			{
				this.SaveOrUpdate(model);
				dalRegexUserBlogContent.SaveOrUpdate(contentModel);
				tx.Commit();
			}
		}

		public IList<RegexUserBlog> ListUserLatestBlogs(Guid userID, int count)
		{
			var query = (from t1 in Session.Query<RegexUserBlog>()
						 orderby t1.CreateDate descending
						 select t1
						).Take(count);
			return query.ToList();
		}

		public IList<RegexUserBlog> ListUserRecommendBlogs(Guid userID, int count)
		{
			var query = (from t1 in Session.Query<RegexUserBlog>()
						 orderby t1.Recommend descending
						 select t1
						).Take(count);
			return query.ToList();
		}
	}
}
		